﻿/**************************************************************************************
 * OfficialFileResultHelper.cs
 * An extension class to extract the url and error information from the additional information string output parameter
 * used on the SPFile.SendToOfficialFile method.
 * Jaime Alberto Jaramillo Zapata (jjaramillo.informatica-tecnologia.com)
 * Created on 02/02/2012.
 * Last update on 02/02/2012.
 **************************************************************************************/

using System.Xml.Linq;

namespace MS.InformationManagement.Support
{

    /// <summary>
    /// An extension class to extract the url and error information from the additional information string output parameter
    /// used on the SPFile.SendToOfficialFile method.
    /// </summary>
    internal static class OfficialFileResultHelper
    {
        /// <summary>
        /// Gets the record URL and error details from the addtional information string out parameter.
        /// </summary>
        /// <param name="additionalInformation">The additional information string.</param>
        /// <returns>An 2 position string array containing in the first position the record url on the record center site,
        /// and in the second position the error details</returns>
        public static string[] GetRecordUrlAndErrorDetails(this string additionalInformation) {
            string[] information = new string[2];
            XDocument xInformation = XDocument.Parse(additionalInformation);
            information[0] = xInformation.Root.Element("Url").Value;
            information[1] = xInformation.Root.Element("Error").Value;
            return information;
        }

        /// <summary>
        /// Gets the record URL from the additional information string out parameter.
        /// </summary>
        /// <param name="additionalInformation">The additional information string.</param>
        /// <returns>The record url on the record center site</returns>
        public static string GetRecordUrl(this string additionalInformation){
            string url = string.Empty;
            XDocument xInformation = XDocument.Parse(additionalInformation);
            url = xInformation.Root.Element("Url").Value;
            return url;
        }

    }
}
